package cn.fl.warrant.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.fl.warrant.service.IArcBscInfoService;
import cn.fl.warrant.transform.ArcBscInfoVOTransform;
import cn.fl.warrant.vo.ArcBscInfoVO;
import fl.warrant.facade.archive.api.IArcBscInfoApiService;
import fl.warrant.facade.archive.condition.ArcBscInfoQueryCondition;
import fl.warrant.facade.archive.condition.PrjContCfgMQC;
import fl.warrant.facade.archive.dto.ArcBscInfoDTO;

/**
 * @Description: 档案基础信息(旧表：T_Data_List) 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class ArcBscInfoServiceImpl implements IArcBscInfoService {
	
	private static final Logger logger = LoggerFactory.getLogger(IArcBscInfoService.class);
	
	/**
	 * 数据字典
	 */
	@Autowired
	private ISysDictionaryApiService sysDictionaryApi;
	
	@Autowired
	private IArcBscInfoApiService arcBscInfoApiService;
	
	
	/**
	 * 根据字段代码组获取代码值集合
	 * @param grpCd 代码组值
	 * @param sysCd 系统代码
	 * @param orgCd 组织结构代码
	 * @return 值
	 * @throws BaseException
	 */
	@Override
	public List<KeyValueVO> getKvList(String sysCd, String orgCd,String grpCd) throws BaseException {
		List<KeyValueVO>  keyValueList = null;
		List<SysDictionaryDTO>  dictionaryList = this.sysDictionaryApi.searchGroup(sysCd, orgCd, grpCd);
		if(CollectionUtils.isNotEmpty(dictionaryList)){
			keyValueList = new ArrayList<>();
			for (SysDictionaryDTO sysDictionaryDTO : dictionaryList) {
				KeyValueVO keyValue = new KeyValueVO();
				keyValue.setKey(sysDictionaryDTO.getCode());
				keyValue.setValue(sysDictionaryDTO.getCodeNm());
				keyValueList.add(keyValue);
			}
		}
		return keyValueList;
	}
	
	public List<KeyValueVO> getKvList(String grpCd, String filterCodeAttr1, String sysCd, String orgCd) throws BaseException {
		return  this.sysDictionaryApi.getKvListWithAttr1(grpCd,  filterCodeAttr1,  sysCd,  orgCd);
	}
	
	
	@Override
	public ArcBscInfoVO selectById(Long id) throws BaseException{
		return ArcBscInfoVOTransform.toVO(arcBscInfoApiService.selectById(id));
	}

	@Override
	public Long add(ArcBscInfoVO entity) throws BaseException{
		return this.arcBscInfoApiService.add(ArcBscInfoVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		return this.arcBscInfoApiService.removeById(id);
	}
	


	@Override
	public boolean update(ArcBscInfoVO entity) throws BaseException{
		return this.arcBscInfoApiService.update(ArcBscInfoVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		return this.arcBscInfoApiService.searchListPage(page);
	}
	
	
	
	public List<ArcBscInfoDTO> searchList(ArcBscInfoQueryCondition condition) throws BaseException {
		return this.arcBscInfoApiService.searchList(condition);
	}
	
	/**
	 * 项目合同配置编号列表
	 * 
	 * @return
	 */
	public List<Map<String, Object>> selectPrjContCfgList(PrjContCfgMQC condition) throws BaseException {
		return this.arcBscInfoApiService.selectPrjContCfgList(condition);
	}
}
